let token = sessionStorage.getItem("token");
let userId = sessionStorage.getItem("user_id");

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}

$(function () {


let due_idd = "";
    $.ajax({
        async: false,
        url: testurl + "due/list_nopage",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({}),
        success: function (data) {
            $.each(data.obj, function (index, value) {
                if (value.current_flag === "1") {
                    $(".current_jie").html(value.name);
                    due_idd = value.id;
                }
            });
     
        }
    });
  

    $.ajax({
        async: false,
        url: testurl + "due/ci/list_nopage",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({
            "due_id": due_idd//届
        }),
        success: function (data) {
            $.each(data.obj, function (index, value) {
                if (value.current_flag === "1") {
                    $(".current_ci").html(value.name);
                } 
            });
        
        }
    })





    //接收URL中的参数id
    let motion_id = getUrlParam('id');
    let str = "";
    let str2 = "";
    let str3 = "";
    $.ajax({
        url: testurl + "motion/detail",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({
            "id": motion_id,//议案id
            "user_id": userId//办理单位id
        }),
        success: function (data) {
            $("#rds_assign_times").html(data.obj.rds_assign_times);
            $(".latest_reply_time").html(data.obj.latest_reply_time);
            $("#rds_assign_remark").html(data.obj.rds_assign_remark);
            $("#reply_time").html(data.obj.reply_times);
            $("#editor_id3").html(data.obj.content);
            $("#zb_handler").html(data.obj.zb_handler);
            $("#xb_handler").html(data.obj.xb_handler);
            $("#this_handler").html(data.obj.this_handler);
            $("#this_status").html(data.obj.this_status);
            $("#motion_type2").val(data.obj.motion_type);
            $("#no").val(data.obj.no);
            $("#class_no").val(data.obj.class_no);
            $("#title2").val(data.obj.title);
            $("#leader_name").val(data.obj.leader_name);
            $("#db_num").val(data.obj.db_num);
            $("#zip_code2").val(data.obj.zip_code);
            $("#phone2").val(data.obj.phone);
            $("#dw_zw2").html(data.obj.dw_zw);
            $("#email222").html(data.obj.email);
            $("#rds_check_ideas").html(data.obj.rds_check_ideas);
            $("#hope_dw").html(data.obj.hope_bldws);
            $("#address2").val(data.obj.address);
            $("#deputy_team2").val(data.obj.team_name);
            $("#deputy_no2").val(data.obj.deputy_no);
            $("#hot_words2").val(data.obj.hot_wordss);
            $("#commit_date2").val(data.obj.commit_date);
            $.each(data.obj.fileList, function (index, value) {
                str += "<a download href=\"" + value.path + "\">" + value.name + "</a>";
            });
            $("#fileList").html(str);
            if (data.obj.is_open === "2") {

                $(".is_open5").eq(0).attr("checked", "");
            } else if (data.obj.is_open === "1") {
                $(".is_open5").eq(1).attr("checked", "");
            }
            if (data.obj.from_way === "1") {
                $(".from_way5").eq(0).attr("checked", "");
            } else if (data.obj.from_way === "2") {
                $(".from_way5").eq(1).attr("checked", "");
            } else if (data.obj.from_way === "3") {
                $(".from_way5").eq(2).attr("checked", "");
            }
            if (data.obj.many_year === "1") {
                $(".many_year5").eq(0).attr("checked", "");
            } else if (data.obj.many_year === "2") {
                $(".many_year5").eq(1).attr("checked", "");
            } else if (data.obj.many_year === "3") {
                $(".many_year5").eq(2).attr("checked", "");
            }
            if (data.obj.strong_link === "1") {
                $("#strong_link4").attr("checked", "");
            }
            if (data.obj.no_reply === "1") {
                $("#no_reply4").attr("checked", "");
            }
            $.each(data.obj.linkerList, function (index, value) {
                str2 += " <tr>\n" +
                    "                                <td>" + value.realname + "</td>\n" +
                    "                                <td>" + value.address + "</td>\n" +
                    "                                <td>" + value.phone + "</td>\n" +
                    "                            </tr>"
            });
            $("#show8").html(str2);


            $.each(data.obj.handlerList, function (index, value) {

                if (value.reply_date === undefined) {
                    value.reply_date = "";
                }
                if (value.reply_type === undefined) {
                    value.reply_type = "";
                }
                str3 += " <tr>\n";
                if (value.read_status === "0") {
                    str3 += "<td title=\"办理单位未查看\"><img src=\"./assets/img/newmail.gif\"></td>\n";
                } else if (value.read_status === "1") {
                    str3 += "<td title=\"办理单位已查看\"><img src=\"./assets/img/readmail.gif\"></td>\n";
                }

                str3 += "                                <td>" + value.type_name + "</td>\n" +
                    "                                <td>" + value.realname + "</td>\n" +
                    "                                <td>" + value.status_name + "</td>\n" +
                    "                                <td>" + value.reply_type + "</td>\n" +
                    "                                <td>" + value.reply_date + "</td>\n" +
                    "                            </tr>";
            });
            $("#show9").html(str3);
        }
    })
    //499 935
});